package com.example.qxfw.nyqx.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.qxfw.common.entity.ny.CropyieldFcst;
import com.example.qxfw.nyqx.mapper.CropyieldFcstMapper;
import com.example.qxfw.nyqx.service.CropyieldFcstService;
import com.example.qxfw.nyqx.vo.CropYieldFcstListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CropyieldFcstServiceImpl implements CropyieldFcstService {

    @Autowired
    private CropyieldFcstMapper cropyieldFcstMapper;

    @Override
    public List<String> getYield(String stationId, long year, String cropName, String type) {
        return cropyieldFcstMapper.selectYield(stationId, year, cropName, type);
    }

    @Override
    public List<String> getYield1(String stationId, long year, String cropName) {
        return cropyieldFcstMapper.selectYield1(stationId, year, cropName);
    }

    @Override
    public List<CropyieldFcst> getList(Integer year, String cropName, String type) {
        return cropyieldFcstMapper.selectList(Wrappers.<CropyieldFcst>lambdaQuery()
                .eq(CropyieldFcst::getYear,year)
                .eq(CropyieldFcst::getCropname,cropName)
                .like(CropyieldFcst::getType,type));
    }

    @Override
    public List<CropyieldFcst> getList1(String year1, String year2, String stationId, String type) {
        return cropyieldFcstMapper.selectList1(year1, year2, stationId, type);
    }

    @Override
    public List<CropyieldFcst> getList2(String year, String stationId, String type) {
        return cropyieldFcstMapper.selectList(Wrappers.<CropyieldFcst>lambdaQuery()
                .eq(CropyieldFcst::getYear,year)
                .eq(CropyieldFcst::getStationid,stationId)
                .eq(CropyieldFcst::getCropname,"双季晚稻")
                .like(CropyieldFcst::getType,type));
    }

    @Override
    public List<CropyieldFcst> getList3(String year, String stationId) {
        return cropyieldFcstMapper.selectList(Wrappers.<CropyieldFcst>lambdaQuery()
                .eq(CropyieldFcst::getYear,year)
                .eq(CropyieldFcst::getStationid,stationId)
                .eq(CropyieldFcst::getCropname,"双季晚稻"));
    }

    @Override
    public List<CropyieldFcst> getList4(long year1, long year2, String stationId, String type, String cropName) {
        return cropyieldFcstMapper.selectList(Wrappers.<CropyieldFcst>lambdaQuery()
                .eq(CropyieldFcst::getStationid,stationId)
                .eq(CropyieldFcst::getCropname,cropName)
                .eq(StringUtils.isNotBlank(type),CropyieldFcst::getType,type)
                .ge(CropyieldFcst::getYear,year1)
                .le(CropyieldFcst::getYear,year2));
    }

    @Override
    public List<CropyieldFcst> getList5(String year, String stationId, String cropName, String type) {
        return cropyieldFcstMapper.selectList(Wrappers.<CropyieldFcst>lambdaQuery()
                .eq(CropyieldFcst::getYear,year)
                .eq(CropyieldFcst::getStationid,stationId)
                .eq(CropyieldFcst::getCropname,cropName)
                .like(CropyieldFcst::getType,type));
    }

    @Override
    public Integer update(CropyieldFcst cropyieldFcst) {
        CropyieldFcst  cropyieldFcst1 = new CropyieldFcst();
        cropyieldFcst1.setYield(cropyieldFcst.getYield());
        cropyieldFcst1.setYear(cropyieldFcst.getYear());
        return cropyieldFcstMapper.update(cropyieldFcst1,Wrappers.<CropyieldFcst>lambdaUpdate()
                .eq(CropyieldFcst::getYear,cropyieldFcst.getYear())
                .eq(CropyieldFcst::getStationid,cropyieldFcst.getStationid())
                .eq(CropyieldFcst::getCropname,cropyieldFcst.getCropname())
                .eq(StringUtils.isNotBlank(cropyieldFcst.getType()),CropyieldFcst::getType,cropyieldFcst.getType()));
    }

    @Override
    public Integer save(CropyieldFcst cropyieldFcst) {
        return cropyieldFcstMapper.insert(cropyieldFcst);
    }

    @Override
    public List<CropYieldFcstListVo> listByYear(long year1, long year2, String stationId, String type, String cropName) {
        return cropyieldFcstMapper.listByYear(year1, year2, stationId, type,cropName);
    }
}
